//
//  LGTabbarViewController.m
//  LuxuryGoods
//
//  Created by 刘星辰 on 2018/5/20.
//  Copyright © 2018年 Future. All rights reserved.
//

#import "LGTabbarViewController.h"
#import "LGNavigationController.h"
#import "LGBaseViewController.h"
#import "UIPageDefines.h"
#import "LGColor.h"
#import "LGTabBar.h"
#import "MyCenterViewController.h"
#import "LGQuickSellViewController.h"
#import "LGClassifyViewController.h"
#import "LGHomeViewController.h"
#import "LGPopView.h"
#import "UIViewController+NavRegister.h"
#import "LGShopViewController.h"
@interface LGTabbarViewController ()

@property (strong,nonatomic)LGQuickSellViewController *quickSellVC;
@property (strong,nonatomic)LGPopView *pop;
@end

@implementation LGTabbarViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    LGTabBar *bar = [[LGTabBar alloc] initWithFrame:self.tabBar.frame];
    bar.tintColor = TOPCAIL_COLOR;
    [self setValue:bar forKey:@"tabBar"];
    WeakObj(self);
    bar.roundAction = ^(UIButton *roundButton) {
        StrongObj(self);
//        self.selectedIndex = 2;
        [self showQuickSellViewController];
    };
    
    [bar setShadowImage:[UIImage new]];
    [bar setBackgroundImage:[UIImage new]];
    
    [self makeChildViewController];
}

- (void)makeChildViewController
{
    //首页
    LGHomeViewController *index = [LGHomeViewController new];
    LGNavigationController *indexNav = [[LGNavigationController alloc] initWithRootViewController:index];
    indexNav.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"首页"
                                                       image:[LGImageFor(@"tab_shouye_normal") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
                                                selectedImage:[LGImageFor(@"tab_shouye_selected") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    //分类
    LGClassifyViewController *classify = [LGClassifyViewController new];
    LGNavigationController *classifyNav = [[LGNavigationController alloc] initWithRootViewController:classify];
    classifyNav.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"分类"
                                                       image:[LGImageFor(@"tab_fenlei_normal") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
                                               selectedImage:[LGImageFor(@"tab_fenlei_seletced") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    //急速买
//    LGQuickSellViewController *buy = [[LGQuickSellViewController alloc] initWithNibName:@"LGQuickSellViewController" bundle:nil];
    LGBaseViewController *buy = [LGBaseViewController new];
    LGNavigationController *buyNav = [[LGNavigationController alloc] initWithRootViewController:buy];
    buyNav.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"极速卖"
                                                          image:nil
                                                  selectedImage:nil];
    
    
    //购物车
    LGShopViewController *shopping = [LGShopViewController new];
    LGNavigationController *shoppingNav = [[LGNavigationController alloc] initWithRootViewController:shopping];
    shoppingNav.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"购物车"
                                                          image:[LGImageFor(@"tab_gouwuche_normal") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
                                                  selectedImage:[LGImageFor(@"tab_gouwuche_selected") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    //我的
    MyCenterViewController *personCenter = [MyCenterViewController new];
    LGNavigationController *personCenterNav = [[LGNavigationController alloc] initWithRootViewController:personCenter];
    personCenterNav.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"我的"
                                                          image:[LGImageFor(@"tab_wode_normal") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
                                                  selectedImage:[LGImageFor(@"tab_wode_selected") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    self.tabBar.tintColor = TOPCAIL_COLOR;
    
     self.viewControllers = @[indexNav,classifyNav,buyNav,shoppingNav,personCenterNav];
    
    self.tabBar.translucent = NO;
    
    
}


- (void)showQuickSellViewController
{
    LGQuickSellViewController *vc = [[LGQuickSellViewController alloc] initWithNibName:@"LGQuickSellViewController" bundle:nil];
    self.quickSellVC = vc;
    [self presentViewController:vc animated:YES completion:^{
        
    }];
//    LGPopView *pop = [LGPopView new];
//    LGNavigationController *nav = self.selectedViewController.view
//    [pop addInView:self.selectedViewController.view withContentView:vc.view];
//    [pop showWithDidShowBlock:^(LGPopView *view) {
//       [self.tabBar setHidden:YES];
//    }];
//
    
    vc.closeAction = ^(LGQuickSellViewController *vc) {
       
        
    };
     WeakObj(self);
    vc.gotoAciton = ^(LGBaseViewController *vc) {
         StrongObj(self);
        LGNavigationController *nav = self.selectedViewController;
        [nav pushViewController:vc animated:YES];
    };
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
